package org.example.innovate.util;

import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class OSSClientUtil implements InitializingBean {
    private static final Logger logger = LoggerFactory.getLogger(OSSClientUtil.class);

    // 使用@Value注解从配置文件中读取值
    @Value("${aliyun.oss.endpoint}")
    private String endpoint;

    @Value("${aliyun.oss.access-key-id}")
    private String accessKeyId;

    @Value("${aliyun.oss.access-key-secret}")
    private String accessKeySecret;

    @Value("${aliyun.oss.bucket-name}")
    private String bucketName;
    //阿里云图片文件存储目录
    // private String homeImageDir = "community/";

    // 定义私有静态变量，并通过静态方法访问
    private static String END_POINT;
    private static String ACCESS_KEY_ID;
    private static String ACCESS_KEY_SECRET;
    private static String BUCKET_NAME;

    @Override
    public void afterPropertiesSet() throws Exception {
        if (endpoint == null || endpoint.isEmpty() ||
                accessKeyId == null || accessKeyId.isEmpty() ||
                accessKeySecret == null || accessKeySecret.isEmpty() ||
                bucketName == null || bucketName.isEmpty()) {
            throw new IllegalArgumentException("OSS configuration is incomplete.");
        }

        END_POINT = endpoint;
        ACCESS_KEY_ID = accessKeyId;
        ACCESS_KEY_SECRET = accessKeySecret;
        BUCKET_NAME = bucketName;
    }

    // 提供静态方法访问配置
    public static String getEndPoint() {
        return END_POINT;
    }

    public static String getAccessKeyId() {
        return ACCESS_KEY_ID;
    }

    public static String getAccessKeySecret() {
        return ACCESS_KEY_SECRET;
    }

    public static String getBucketName() {
        return BUCKET_NAME;
    }

}
